import React from 'react'
import { Switch, Route, Redirect } from 'react-router'
const beforeEnter = (item, History) => {
    if(item.isLogin){
        const user=window.localStorage.getItem('user')
        if(!user){
            return <Redirect to="/login"/>
        }
    }
    return <item.component {...History} routes={item.children ? item.children : []}>
        <ReateView routes={item.children ? item.children : []}></ReateView>
    </item.component>
}
const ReateView = (props) => {
    const { routes } = props
    return <Switch>
        {
            routes.map((item, idx) => item.path ? <Route
                key={idx}
                path={item.path}
                render={(History) => beforeEnter(item,History)}
            >

            </Route> : <Redirect {...item} key={idx} />)
        }
    </Switch>
}
export default ReateView